package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.enums.DWaybillStatusEnum;
import cn.huiyunche.base.service.interfaces.OtmMonitoringService;
import cn.huiyunche.base.service.mappers.ext.OtmMonitoringMapper;
import cn.huiyunche.base.service.vo.MonitoringOrderVo;
import cn.huiyunche.base.service.vo.PageVo;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OtmMonitoringServiceImpl implements OtmMonitoringService {

    @Autowired
    OtmMonitoringMapper otmMonitoringMapper;

    @Override
    public Map<String,Object> monitoringOrder(PageVo pageVo,String shipmentId, String beginDate, String endDate) {
        Map<String, Object> result=new HashMap<>();
        Map<String,Object> params=new HashMap<>();
        if (StringUtils.isBlank(beginDate)){
            throw new BusinessException("开始时间不能为空");
        }
        if (StringUtils.isBlank(endDate)){
            throw new BusinessException("结束时间不能为空");
        }
        params.put("beginDate",beginDate);
        params.put("endDate",endDate);
        if (StringUtils.isNotBlank(shipmentId)){
            String[] split = shipmentId.split(",");
            List<String> strings = Arrays.asList(split);
            params.put("orderCode",strings);
        }
        params.put("limitStart", pageVo.getStartIndex());
        params.put("limitEnd", pageVo.getPageSize());
        pageVo.setTotalRecord(otmMonitoringMapper.orderCount(params));
        List<MonitoringOrderVo> monitoringOrderVos = otmMonitoringMapper.orderList(params);
        result.put("page",pageVo);
        result.put("data",monitoringOrderVos);
        return result;
    }
}
